package org.esgl3d;

import org.esgl3d.core.AndroidResourceResolver;
import org.esgl3d.primitives.Box;
import org.esgl3d.primitives.Pyramid;
import org.esgl3d.rendering.RenderActivity;
import org.esgl3d.rendering.Renderer;
import org.esgl3d.scene.MeshNode;
import org.esgl3d.scene.Scene;
import org.esgl3d.ui.BitmapFont;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory.Options;
import android.os.Bundle;

public class ExTexturedBoxActivity extends RenderActivity {
	private MeshNode box;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);		
	}
	
	@Override
	public void setupScenegraph() {
		
		AndroidResourceResolver resolver = new AndroidResourceResolver(getAssets());
		
		// get our renderer
		Renderer cur = getRenderer();
		
		// load a bitmap (straightforward android code)
		Options opt = new  Options();
		opt.inPreferredConfig = Config.RGB_565;
		
		Bitmap font = BitmapFactory.decodeStream(resolver.getResourceStream("nehe_texture_crate.png"));
		
	
		// create a new scene
		Scene myScene = new Scene();
		
		Mesh boxMesh = Box.createTexturedBox(cur);
		
		// create a new box and set a texture
		box = new MeshNode();
		box.setGeometry(boxMesh);
		boxMesh.setTexture(cur.getTextureManager().addImage(font, false));
		
		// add the box to the scene
		myScene.addChild(box);
		
		// set the scene to be rendered
		cur.setScene(myScene);
	}
	
	@Override
	public void updateScenegraph() {

		// rotate our box a little
		box.rotate(1, 0.25f, 1, 0);
	}
}
